package eSchool.GUI.Controls;

import eSchool.BL.CriteriosPesquisa;
import javax.swing.table.TableModel;

public class panSearchGrid extends JPanelExtended {
    
    TableModel tableModel = null;
    
    public panSearchGrid() {
        initComponents();
    }
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ftxtIdentificador = new javax.swing.JFormattedTextField();
        btnPesquisar = new javax.swing.JButton();
        jComboBoxExtended1 = new eSchool.GUI.Controls.JComboBoxExtended();

        ftxtIdentificador.setToolTipText("Número de indentificação"); // NOI18N

        btnPesquisar.setText("Pesquisar"); // NOI18N
        btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarActionPerformed(evt);
            }
        });

        jComboBoxExtended1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jComboBoxExtended1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ftxtIdentificador, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnPesquisar)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxExtended1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPesquisar)
                    .addComponent(ftxtIdentificador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarActionPerformed
        CriteriosPesquisa cr = new CriteriosPesquisa();
        cr.add(jComboBoxExtended1.getSelectedValue().toString(), ftxtIdentificador.getText());
        eventListner.SearchButtonClickEvent(this, cr);
    }//GEN-LAST:event_btnPesquisarActionPerformed
    
    public void setDataSource(TableModel tableModel){
        this.tableModel = tableModel;        
    }
    
    public void dataBind(){
        jComboBoxExtended1.removeAllItems();
        for(int i = 0; i<tableModel.getColumnCount(); i++){
            jComboBoxExtended1.addItem(tableModel.getColumnName(i), tableModel.getColumnName(i));
        }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JFormattedTextField ftxtIdentificador;
    private eSchool.GUI.Controls.JComboBoxExtended jComboBoxExtended1;
    // End of variables declaration//GEN-END:variables
    
}
